package blatt5;

import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import java.util.Enumeration;

public class KatzUndMaus extends Frame {
	public static final int FRAMEWIDTH = 600;
	public static final int FRAMEHEIGHT = 400;
	public static final int SPEED = 5;
	public static final int RADIUS = 8;
	// die beiden Baelle
	private SpielBall ball1;
	private SpielBall ball2;
	// Fuer das DoubleBuffering
	private Graphics bufferGraphics;
	private Image buffer;

	private void bufferInit() { // wir zeichnen in einen Puffer

		buffer = this.createImage(FRAMEWIDTH, FRAMEHEIGHT);
		bufferGraphics = buffer.getGraphics();
	}

	public static void main(String[] args) {
		new KatzUndMaus().show();
	}

	public KatzUndMaus() {
		setTitle("Katz und Maus");
		setSize(FRAMEWIDTH, FRAMEHEIGHT);
		setBackground(Color.white);

		ball1 = new SpielBall(20, FRAMEHEIGHT - 20, RADIUS, 0, 0, FRAMEWIDTH,
				FRAMEHEIGHT);

		ball1.setRolle(new Maus(ball1, this));
		ball1.setColor(Color.blue);

		ball2 = new SpielBall(FRAMEWIDTH - 20, 40, RADIUS, 0, 0, FRAMEWIDTH,
				FRAMEHEIGHT);

		ball2.setRolle(new Katze(ball2, ball1));
		ball2.setColor(Color.red);
		repaint();
	}

	public void paint(Graphics g) {
		if (buffer == null)
			bufferInit();

		// loesche Puffer
		bufferGraphics.setColor(Color.white);
		bufferGraphics.fillRect(0, 0, FRAMEWIDTH, FRAMEHEIGHT);
		ball1.moveSpielBall();
		ball2.moveSpielBall();
		ball1.paintSpielBall(bufferGraphics);
		ball2.paintSpielBall(bufferGraphics);
		g.drawImage(buffer, 0, 0, this);

		try {
			Thread.sleep(10);
		} catch (InterruptedException e) {
			System.exit(0);
		}

		repaint();
	}

	public void update(Graphics g) {
		paint(g);
	}
}